package com.sinothk.droid.chart.pieChart;

import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.ValueFormatter;

public class AppDefaultValueFormatter extends ValueFormatter {

    //    public DecimalFormat mFormat;
    private PieChart pieChart;
    private String unitStr;

    public AppDefaultValueFormatter() {
//        mFormat = new DecimalFormat("###,###,##0");
    }

    public AppDefaultValueFormatter(String unitStr) {
        this.unitStr = unitStr;
//        mFormat = new DecimalFormat("###,###,##0");
    }

    // Can be used to remove percent signs if the chart isn't in percent mode
    public AppDefaultValueFormatter(PieChart pieChart) {
        this();
        this.pieChart = pieChart;
    }

//    @Override
//    public String getFormattedValue(float value) {
//        return mFormat.format(value) + " %";
//    }

    @Override
    public String getPieLabel(float value, PieEntry pieEntry) {
//        if (pieChart != null && pieChart.isUsePercentValuesEnabled()) {
//            // Converted to percent
//            return getFormattedValue(value);
//        } else {
//            // raw value, skip percent sign
//            return mFormat.format(value);
//        }

        if (pieChart != null && pieChart.isUsePercentValuesEnabled()) {
            // Converted to percent
            return getFormattedValue(value);
        } else {
            // raw value, skip percent sign
            if (this.unitStr != null && this.unitStr.length() > 0) {
                return ((int) pieEntry.getY()) + this.unitStr;
            } else {
                return ((int) pieEntry.getY()) + "";
            }
        }
    }
}

